package com.random.fox.whatspay.greendao;

/**
 *
 */

import android.database.sqlite.SQLiteDatabase;

import com.random.fox.whatspay.bean.Account;
import com.random.fox.whatspay.bean.Categories;
import com.random.fox.whatspay.bean.Cost;
import com.random.fox.whatspay.greendao.dao.AccountDao;
import com.random.fox.whatspay.greendao.dao.CategoriesDao;
import com.random.fox.whatspay.greendao.dao.CostDao;

import java.util.Map;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.AbstractDaoSession;
import de.greenrobot.dao.identityscope.IdentityScopeType;
import de.greenrobot.dao.internal.DaoConfig;

/**
 * {@inheritDoc}
 *
 * @see de.greenrobot.dao.AbstractDaoSession
 * Created by 渠 on 2014/11/7.
 */
public class DaoSession extends AbstractDaoSession {


    private final DaoConfig accountDaoConfig;
    private final DaoConfig costDaoConfig;
    private final DaoConfig categoriesConfig;

    private final AccountDao accountDao;
    private final CostDao costDao;
    private final CategoriesDao categoriesDao;


    public DaoSession(SQLiteDatabase db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
            daoConfigMap) {
        super(db);
        accountDaoConfig = daoConfigMap.get(AccountDao.class).clone();
        accountDaoConfig.initIdentityScope(type);

        costDaoConfig = daoConfigMap.get(CostDao.class).clone();
        costDaoConfig.initIdentityScope(type);

        categoriesConfig = daoConfigMap.get(CategoriesDao.class).clone();
        categoriesConfig.initIdentityScope(type);

        accountDao = new AccountDao(accountDaoConfig, this);
        costDao = new CostDao(costDaoConfig, this);
        categoriesDao = new CategoriesDao(categoriesConfig,this);

        registerDao(Account.class, accountDao);
        registerDao(Cost.class, costDao);
        registerDao(Categories.class,categoriesDao);
    }

    public void clear() {
        accountDaoConfig.getIdentityScope().clear();
        costDaoConfig.getIdentityScope().clear();
        categoriesConfig.getIdentityScope().clear();
    }

    public AccountDao getAccountDao() {
        return accountDao;
    }

    public CostDao getCostDao(){
        return costDao;
    }

    public CategoriesDao getCategoriesDao(){
        return categoriesDao;
    }
}
